﻿{extend name="public:base" /}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ibox-style">
                <style lang="less">
                    .all{
                        display: flex;
                        flex-direction: column;
                        .update-btn{
                            margin-bottom: 10px;
                            width: 314px;
                        }
                    }

                    .icon-huifu {
                        font-size: 18px;
                        cursor: pointer;
                        padding: 0;
                        margin-left: 20px;
                    }

                    .ibox-style {
                        display: flex;
                        align-items: center;
                        justify-content: center;
                    }

                    .content {
                        display: flex;
                        justify-content: space-between;
                        width: 55vw;
                        height: 75vh;
                        border-radius: 10px;
                        background: #fff;
                        position: relative;

                        .video-box {
                            height: 100%;
                            width: 30%;
                            border-radius: 10px 0 0 10px;
                            border-right: 1px solid rgba(0, 0, 0, .1);
                            padding-top: 20px;
                            display: flex;
                            flex-direction: column;

                            .tab-box {
                                height: 10%;
                                display: flex;
                                justify-content: space-between;

                                .tab-item {
                                    flex: 1;
                                    height: 34px;
                                    line-height: 34px;
                                    text-align: center;
                                    font-size: 16px;
                                    cursor: pointer;
                                }

                                .active {
                                    border-bottom: 2px solid #1ab394;

                                }
                            }

                            .video-list {
                                flex: 1;
                                overflow-y: auto;
                                padding: 0 10px;

                                .active {
                                    background: #ccf3eb;
                                }
                            }
                        }

                        .box {
                            display: flex;
                            margin-bottom: 10px;
                            padding-right: 20px;
                            cursor: pointer;

                            &:hover {
                                background: #f5f5f5;
                            }

                            &:last-child {
                                margin-bottom: 0;
                            }

                            .cover {
                                height: 70px;
                                width: 50px;
                                min-width: 0;
                                object-fit: cover;
                                border-radius: 6px;
                                margin-right: 12px;
                                flex-shrink: 0;
                            }

                            .desc-box {
                                display: flex;
                                flex-direction: column;
                                justify-content: space-between;
                                width: calc(100% - 60px);
                                padding: 10px 0;

                                .desc {
                                    white-space: nowrap;
                                    overflow: hidden;
                                    text-overflow: ellipsis;
                                    font-size: 14px;
                                }

                                .bottom {
                                    display: flex;
                                    justify-content: space-between;
                                    align-items: center;
                                    font-size: 12px;

                                    .icon-huifu {
                                        font-size: 14px;
                                        margin-right: 5px;
                                    }
                                }
                            }

                        }

                        .comment-box {
                            flex: 1;
                            border-radius: 0 10px 10px 0;
                            padding: 20px;
                            overflow: hidden;

                            .box {
                                padding-bottom: 20px;
                                border-bottom: 1px solid rgba(0, 0, 0, .1);

                                .cover {
                                    height: 120px;
                                    width: 80px
                                }

                                .desc-box {
                                    .desc {
                                        white-space: normal;
                                        overflow: hidden;
                                        text-overflow: ellipsis;
                                        display: -webkit-box;
                                        -webkit-box-orient: vertical;
                                        -webkit-line-clamp: 2;
                                    }
                                }
                            }

                            .head-box {
                                display: flex;
                                justify-content: space-between;
                                align-items: center;
                                height: 40px;

                                .comment-count {
                                    .count {
                                        margin: 0 5px;
                                        font-size: 16px;
                                    }
                                }

                                .btn {
                                    padding: 5px 30px;
                                    border-radius: 6px;
                                    background: #1ab394;
                                    color: #fff;
                                }
                            }

                        }

                        .chat-box {
                            padding: 10px 0;
                            display: flex;
                            flex-direction: column;
                            overflow-y: auto;
                            height: calc(100% - 190px);

                            .main {
                                width: 100%;
                                padding: 0 20px;
                                margin-bottom: 20px;

                                &:last-child {
                                    margin-bottom: 0;
                                }

                                .row {
                                    .avatar {
                                        height: 50px;
                                        width: 50px;
                                        border-radius: 50%;
                                        object-fit: cover;
                                        flex-shrink: 0;
                                        margin-right: 20px;
                                    }

                                    .chat {
                                        flex: 1;
                                        padding-bottom: 10px;
                                        border-bottom: 1px solid rgba(0, 0, 0, .1);

                                        .info-box {
                                            display: flex;

                                            .author {
                                                margin: 0 10px;
                                                color: #1ab394;
                                            }

                                            .time {
                                                color: #999;
                                            }
                                        }

                                        .comment-content {
                                            display: flex;
                                            margin-top: 16px;
                                            justify-content: space-between;
                                        }
                                    }
                                }

                                .son {
                                    padding: 10px 0;
                                    width: calc(100% - 40px);
                                    float: right;
                                    border-bottom: 1px solid rgba(0, 0, 0, .1);

                                    .avatar {
                                        height: 40px;
                                        width: 40px;
                                        border-radius: 50%;
                                        object-fit: cover;
                                        flex-shrink: 0;
                                    }

                                    .chat {
                                        flex: 1;
                                        padding-bottom: 0;
                                        border-bottom: none;
                                    }
                                }
                            }
                        }

                        /*评论弹框*/

                        .comment-model {
                            background: rgba(0, 0, 0, 0.4);
                            position: absolute;
                            top: 0;
                            left: 0;
                            bottom: 0;
                            right: 0;
                            border-radius: 10px;
                            z-index: 99;
                            display: flex;
                            align-items: center;
                            justify-content: center;

                            .model-content {
                                width: 60%;
                                height: auto;
                                background: #fff;
                                border-radius: 10px;
                                position: relative;
                                display: flex;
                                flex-direction: column;
                                align-items: center;
                                padding-bottom: 40px;

                                .icon-close {
                                    position: absolute;
                                    top: 10px;
                                    right: 10px;
                                    cursor: pointer;
                                    font-size: 24px;
                                    font-weight: bold;
                                }

                                .chat-box {
                                    height: auto;
                                    width: 70%;
                                    margin-top: 60px;

                                    .chat {
                                        border-bottom: none;
                                    }
                                }

                                .chat-content {
                                    padding: 10px 10px 20px 10px;
                                    width: 70%;
                                    height: 150px;
                                    border: 1px solid rgba(0, 0, 0, .1);
                                    margin-top: 20px;
                                    border-radius: 10px;

                                    .textarea {
                                        width: 100%;
                                        height: 70%;
                                        border: none;
                                        outline: none;
                                        resize: none;
                                    }

                                    .btn-box {
                                        display: flex;
                                        justify-content: flex-end;
                                        margin-top: 10px;

                                        .btn {
                                            padding: 5px 30px;
                                            border-radius: 6px;
                                            background: #1ab394;
                                            color: #fff;
                                        }
                                    }
                                }

                                .quick-reply-box {
                                    display: flex;
                                    flex-direction: column;
                                    margin-top: 20px;
                                    width: 70%;
                                    border: 1px solid rgba(0, 0, 0, .1);
                                    border-radius: 10px;
                                    padding: 10px 10px 0 10px;

                                    .quick-reply-title {
                                        padding-bottom: 10px;
                                        border-bottom: 1px solid rgba(0, 0, 0, .1);
                                    }

                                    .quick-reply {
                                        display: flex;
                                        flex-direction: column;
                                        max-height: 200px;
                                        overflow-y: auto;

                                        .item {
                                            display: flex;
                                            justify-content: space-between;
                                            align-items: center;
                                            padding: 10px 0;
                                            border-bottom: 1px solid rgba(0, 0, 0, .1);

                                            &:last-child {
                                                border-bottom: none;
                                            }

                                            .msg {
                                                width: 65%;
                                            }

                                            .btn-box {
                                                display: flex;
                                                justify-content: flex-end;
                                                flex: 1;
                                                flex-shrink: 0;

                                                .btn {
                                                    padding: 2px 8px;
                                                    border-radius: 6px;
                                                    background: #1ab394;
                                                    color: #fff;
                                                }

                                                .ai-btn {
                                                    background: #fa9d3b;
                                                    margin-right: 5px;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                </style>

                <div class="all">
                    <a href="javascript: void(0)" onclick="updateVideoAndComment()" class="update-btn btn btn-primary">评论数据一键同步</a>

                    <div class="content">
                        <div class="video-box">
                            <div class="tab-box">
                                <div class="tab-item active">视频</div>
                                <div class="tab-item">图片</div>
                            </div>
                            <div class="video-list">
                                {volist name="video_list" id="vo"}
                                <div class="box video-list-box" onclick="changeVideo('{$vo.id}', {$key})">
                                    <img class="cover" src="{$vo.thumbUrl}" alt="">
                                    <div class="desc-box">
                                        <div class="desc">{$vo.description}</div>
                                        <div class="bottom">
                                            <div class="time">{$vo.createTime|timeFormat}</div>
                                            <div class="comment_count">
                                                <i class="iconfont icon-huifu "></i><span>{$vo.commentCount}</span>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                {/volist}
                            </div>
                        </div>
                        <div class="comment-box">
                            <div id="header">
                                <div class="box">
                                    <img class="cover" src="https://finder.video.qq.com/251/20304/stodownload?encfilekey=oibeqyX228riaCwo9STVsGLIBn9G5YG8Znhiaw8M6lgcKEEklJibLeL8M7CaUeHhOGticI3G6wXO3LnGh1VtPeibJNiayscIc9RdGaTAiaxsCu74k4U4xJaNyFoJuibTXcmfHrvum7TwwicLl1NiaY&token=6xykWLEnztJic14j5EuwldIW1rEhty9uhokngQZTiaMgxhcWUkTdSibUvibKg0fEoPfibuMTyZO34S4A150qpS22wokibsHdA1WMMnwmmFvibiaOKs8jzfKYz1amAX9ExBnR77eS&idx=1&hy=SZ&m=934e359c7522026a47780fe6f6e162b6&uzid=2" alt="">
                                    <div class="desc-box">
                                        <div class="desc">小元旦1岁啦！有的小猫在手心里捧着捧着就长大了，两个月大时才1斤，带去打疫苗医生都说跟个小老鼠似的。从小到大一直调皮捣蛋~挺好挺好！小元旦1岁啦！有的小猫在手心里捧着捧着就长大了，两个月大时才1斤，带去打疫苗医生都说跟个小老鼠似的。从小到大一直调皮捣蛋~挺好挺好！</div>
                                        <div class="bottom">
                                            <div class="time">2024/12/07 23:50</div>
                                        </div>
                                    </div>
                                </div>
                                <div class="head-box">
                                    <div class="comment-count">共<span class="count">7</span>条评论</div>
                                    <!--                                <div class="btn" onclick="openCommentModel()">写评论</div>-->
                                </div>
                            </div>

                            <div id="chat-box" class="chat-box"></div>
                        </div>

                        <!--  评论弹框  -->
                        <div class="comment-model" style="display: none">
                            <div class="model-content">
                                <i class="iconfont icon-close" onclick="closeCommentModel()"></i>
                                <div class="chat-box">
                                    <div class="main">
                                        <div class="row">
                                            <img src="http://wx.qlogo.cn/finderhead/f1Z8IBU40VichWQrD1ib93fMfpf6jCP3lCDiaavdXwaevU/0" class="avatar">
                                            <div class="chat">
                                                <div class="info-box">
                                                    <div class="name">小元旦和大灰狼</div>
                                                    <div class="author">作者</div>
                                                    <div class="time">2024/12/04 20:28</div>
                                                </div>
                                                <div class="comment-content">
                                                    <div>测试小元旦1岁啦！有手心里捧着</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="chat-content">
                                    <textarea class="textarea"></textarea>
                                    <!--  评论id  -->
                                    <input type="hidden" id="comment-id" value="0">
                                    <!--  快捷回复id【用于记录快捷回复使用次数】  -->
                                    <input type="hidden" id="quick-reply-id" value="0">
                                    <div class="btn-box">
                                        <div class="btn" onclick="reply()">发送</div>
                                    </div>
                                </div>

                                <!--快捷-->
                                <div class="quick-reply-box">
                                    <div class="quick-reply-title">快捷回复</div>
                                    <div class="quick-reply">
                                        <div class="item">
                                            <div class="msg">谢谢您的支持谢谢您的支持谢持谢谢您的支持</div>
                                            <div class="btn-box">
                                                <div class="btn ai-btn">AI优化</div>
                                                <div class="btn">使用</div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>{/block}

{block name="js"}
<script>
    var videoIndex = -1;

    if (videoIndex == -1) {
        $('#header').hide();
    } else {
        $('#header').show();
    }

    function chooseVideo() {
        $('.video-list-box').removeClass('active');
        $('.video-list-box').eq(videoIndex).addClass('active');
    }

    function changeVideo(id, key) {
        videoIndex = key;

        chooseVideo();

        $('.comment-box .box .cover').attr('src', $('.video-list-box').eq(key).find('.cover').attr('src'));
        $('.comment-box .box .desc').html($('.video-list-box').eq(key).find('.desc').html());
        $('.comment-box .box .time').html($('.video-list-box').eq(key).find('.time').html());
        $('.head-box .count').html($('.video-list-box').eq(key).find('.desc-box .bottom .comment_count span').html());

        $('#header').show();

        $.post('/index/Api/getCommentToDB', {
            video_id: id
        }, res => {
            renderComment(res.data)
        }, 'json')
    }


    function renderComment(list) {
        var main = '';
        var parentHtml = '';
        var sonHtml = '';
        if (list.length > 0) {
            list.forEach(val => {
                parentHtml = '';
                sonHtml = '';

                parentHtml += `<div class="row">
                                    <img src="${val.commentHeadurl}" class="avatar">
                                    <div class="chat">
                                        <div class="info-box">
                                            <div class="name">${val.commentNickname}</div>
                                            <div class="author">${val.visibleFlag == 1 ? '作者' : ''}</div>
                                            <div class="time">${val.commentCreatetime}</div>
                                        </div>
                                        <div class="comment-content">
                                            <div>${val.commentContent}</div>
                                            <i class="iconfont icon-huifu" onclick="openCommentModel(this, '${val.commentId}')"></i>
                                        </div>
                                    </div>
                                </div>`;

                if (val.son_list.length > 0) {
                    val.son_list.forEach(son => {
                        sonHtml += `<div class="row son">
                                    <img src="${son.commentHeadurl}" class="avatar">
                                    <div class="chat">
                                        <div class="info-box">
                                            <div class="name">${son.commentNickname}</div>
                                            <div class="author">${son.visibleFlag == 1 ? '作者' : ''}</div>
                                            <div class="time">${son.commentCreatetime}</div>
                                        </div>
                                        <div class="comment-content">
                                            <div>${son.commentContent}</div>
                                            <i class="iconfont icon-huifu" onclick="openCommentModel(this, '${son.commentId}')"></i>
                                        </div>
                                    </div>
                                </div>`;
                    })
                }

                main += `<div class="main">${parentHtml}${sonHtml}</div>`
            })
        }
        $('#chat-box').html(main);
    }

    function openCommentModel(_this, commentId) {
        $('#comment-id').val(commentId);

        // 加载中
        layer.load(1);

        new Promise(resolve => {
            var rowHtml = $(_this).parents('.row').clone().html();
            var tempDiv = $('<div>').html(rowHtml);
            tempDiv.find('i').remove();
            $('.comment-model .chat-box .main').html('<div class="row">' + tempDiv.html() + '</div>');

            $.post('/index/Api/getQuickReplyList', {
                commentId
            }, res => {
                if (res.result == 1) {
                    var list = res.data;
                    var html = '';
                    if (list.length > 0) {
                        list.forEach(val => {
                            html += `<div class="item">
                                        <div class="msg">${val.msg}</div>
                                        <div class="btn-box">
                                            <div class="btn ai-btn" onclick="useAIMsg(${val.id}, '${val.msg}')">AI优化</div>
                                            <div class="btn" onclick="useMsg(${val.id}, '${val.msg}')">使用</div>
                                        </div>
                                    </div>`;
                        })
                    }
                    $('.quick-reply').html(html);

                    resolve();
                } else {
                    layer.closeAll();
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json')
        }).then(() => {
            layer.closeAll();

            $('.comment-model').show();
        })


    }

    /**
     * 使用快捷回复
     * @params id 快捷回复id
     * @params msg 快捷回复内容
     * */
    function useMsg(id, msg) {
        $('#quick-reply-id').val(id);
        $('.chat-content .textarea').val(msg);
    }

    /**
     * 使用AI快捷回复
     * */
    function useAIMsg(id, msg) {
        if (!msg) {
            layer.msg('AI回复失败', {icon: 2});
            return false;
        }

        layer.load(1);

        $.post('/index/Api/AIQuickReply', {
            msg
        }, res => {
            layer.closeAll();
            if (res.result == 1) {
                $('#quick-reply-id').val(id);
                console.log(res.data)
                $('.chat-content .textarea').val(res.data);
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'json')
    }

    // 发送回复
    function reply() {
        var commentId = $('#comment-id').val();
        var quickReplyId = $('#quick-reply-id').val();
        var msg = $('.chat-content .textarea').val();

        if (!commentId || !quickReplyId || !msg) {
            layer.msg('缺少参数，发送失败', {icon: 2});
            return false;
        }

        layer.load(1);

        new Promise((resolve) => {
            $.post('/index/Api/comment', {
                commentId, quickReplyId, msg
            }, res => {
                layer.closeAll();
                if (res.result == 1) {
                    var exportId = res.data;
                    layer.msg(res.msg, {icon: 1, time: 1000});
                    resolve(exportId);
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json')
        }).then((exportId) => {
            layer.msg('评论更新中...', {icon: 1, time: 1000});
            layer.load(1);

            $.post('/index/Api/videoCommentList', {
                exportId
            }, res => {
                layer.closeAll();
                if (res.result == 1) {
                    layer.msg(res.msg, {icon: 1, time: 1000}, () => {
                        window.location.reload();
                    });
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json')
        })
    }

    function closeCommentModel() {
        $('.comment-model').hide();
    }
</script>{/block}

